package com.tuyue.police.weixin.controller.page;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2018/3/20.
 * @Modified By:
 */
@RestController
@RequestMapping("/wechat/msg")
public class MsgController {

    @Autowired
    private WxMpService wxService;


    /**
     * oApIO1VMsQOVFA8rm4gUEge2jqJw
     * @return
     * @throws WxErrorException
     */
    @GetMapping("send")
    public boolean send() throws WxErrorException {

        WxMpKefuMessage message = new WxMpKefuMessage();
        message.setMsgType(WxConsts.KefuMsgType.TEXT);
        message.setToUser("obZjo0QAPvwrg0YP1EdN0J2oa51Q");
        message.setContent(
                "欢迎欢迎，热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
        return wxService.getKefuService().sendKefuMessage(message);
    }

    @RequestMapping("/sendTemplate")
    public String createWeiXinCat(@RequestBody WxMpTemplateMessage wxMpTemplateMessage) throws WxErrorException {
        WxMpTemplateMsgService templateMsgService = wxService.getTemplateMsgService();
        return templateMsgService.sendTemplateMsg(wxMpTemplateMessage);
    }

}
